layui.use(['form','layer','upload'], function(){
         var  $ = layui.$;
          var form = layui.form
          ,layer = layui.layer
          ,upload = layui.upload
          ,appTypeDict = {};
           $("#appType").empty();
		   $.getJSON ("../dict/dict.json","", function (data) {  
		     
			    appTypeDict = data.appType;
                $.each (appTypeDict, function (i, item)  
                {   
			        $("#appType").append("<option value='"+i+"'>"+item+"</option>");
                });  
			
			    form.render();
            });
          
		   
		  $("#savebtn").on('click',function(){save();});
		  
		  $("#appName").on('change',function(){
			  var appName = $(this).val();
			  $("#appNumber").val("APP-"+pinyinUtil.getFirstLetter(appName));
		  });
            //执行实例
		  var uploadInst = upload.render({
			elem: '#fileUpload' //绑定元素
			,url: '../file/uploadFile' //上传接口
			,accept:'file'
			,exts: 'apk|ipa'
			,acceptMime :'application/vnd.android.package-archive,application/iphone-package-archive'
			,done: function(res){
			  var file = res.data;
			  $("#fileName").val(file.fileNameOld);
			  $("#fileId").val(file.id);
			}
			,error: function(){
			  //请求异常回调
			}
		  });          

        function  save(){
        	
        	var data = {};
        	var appName = $("#appName").val();
        	if(isBlank(appName)){
        		layer.tips("请填写应用名称","#appName",{
      			  tips: [1, '#FF0000'],
      			  time: 3000
      			});
      		return false;
        	}
        	data['appName'] = appName;
        	
        	var appNumber = $("#appNumber").val();
        	if(isBlank(appNumber)){
        		layer.tips("请填写应用编码","#appNumber",{
        			  tips: [1, '#FF0000'],
        			  time: 3000
        			});
        		return false;
        	}
            data['appNumber'] = appNumber;
            
            var platform = $("#platform").val();
            data['platform'] = platform;
            
            var appType = $("#appType").val();
            data['appType'] = appType;
            
            
            var boundId = $("#boundId").val();
            if(!isBlank(boundId))
            	data['boundId'] = boundId;
            
            var fileId = $("#fileId").val();
            if(isBlank(fileId)){
        		layer.tips("请上传文件","#fileUpload",{
        			  tips: [1, '#FF0000'],
        			  time: 3000
        			});
        		return false;
            }
            data['attachmentId']=fileId;
            
            var editStatus = $("#editStatus").val();
            data['editStatus']=editStatus;
        
            var remark = $("#remark").val();
            data['remark'] = remark;
            
            ajaxPost('../app/saveApp',data,
            	 function(){
            			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            			parent.layer.close(index);
            			parent.initPage();
            			//parent.location.reload();
            		},
            		function(data){
        				parent.layer.alert(data.errorMsg, {
        					icon: 5,
        					title: "错误"
        					});
        	
            		});
        }

});	
		
